<template>
  <div class="app-container">
    <h3 style="">员工导入</h3>
    <el-alert
      title="每次导入仅可添加1000名员工，姓名、手机、入职时间、聘用形式为必填项"
      type="warning"
      show-icon
    />
    <upload-excel-component :on-success="successHandler" />
  </div>
</template>

<script>
import { importEmployees } from '../../api/employees'
import UploadExcelComponent from '@/components/UploadExcel/index.vue'
import { formatExcelDate } from '../../utils/index'
export default {
  name: 'UploadExcel',
  components: { UploadExcelComponent },
  methods: {
    async successHandler(data) {
      const res = data.results.filter(v => {
        v.correctionTime = formatExcelDate(v.correctionTime, '/')
        v.timeOfEntry = formatExcelDate(v.timeOfEntry, '/')
        return true
      })
      await importEmployees(res)
      this.$message.success('导入成功')
      this.$router.push('/employees')
    }
  }
}
</script>

<style lang="scss">
.app-container {
  h3 {
    text-align: center;
  }
  .el-alert {
    margin-bottom: 40px;
  }
}
</style>
